<div class="alert">
<?php
require_once('includes/user_manage.php');

$user->isAdmin or exit("Área reservada a administradores");

$my_category=new admin_category();
$my_category->id=$_GET["category_id"];
$my_category->name=$_POST["name"];
$updated=$my_category->db_update_name();

if ($updated==true) {
	$my_category->db_load();
	$serCategory=json_encode($my_category);
?>
	Categoria actualizada.
	<form id="myEditForm"><input type="hidden" value='<?php print htmlentities($serCategory); ?>' name="serCategory"></form>
<?php
}
else {
?>
	Ocurrió un error.
<?php
}
?>
</div>

<script type="text/javascript">
	var categoryId=<?php echo $my_category->id; ?>;
	var catalogPointer=myCatalog;
	catalogPointer=catalogPointer.moveToChildren("categoryId", categoryId);
	if (!catalogPointer.myCategory.id) {
		catalogPointer=catalogPointer.moveToChildren("selected");
		catalogPointer=catalogPointer.moveToChildren("categoryId", categoryId);
	}
	var serCategory=document.getElementById("myEditForm").serCategory.value;
	catalogPointer.myCategory.setFromArray(JSON.parse(serCategory));
	catalogPointer.myCategory.mySetView(catalogPointer.parentNode.myCategoryView.cloneNode(true));

window.setTimeout(removeAlert,2000,document.getElementById('editCategory'));
function removeAlert(alert) {
	alert.parentNode.removeChild(alert);
}
</script>